package com.java.jvm.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangning
 * @date 2023/5/18 17:03
 * -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
 * Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
 */
public class GCOverheadDemo {
    public static void main(String[] args) {
        int i = 0;
        List<String> list = new ArrayList<>();
        try {
            while (true) {
                list.add(String.valueOf(++i).intern());
            }
        } catch (Throwable e) {
            System.out.println("***********i: " + i);
            e.printStackTrace();
        }
    }
}
